
package com.compuvest.web;

// <editor-fold defaultstate="collapsed" desc="import">
import java.io.Serializable;
// </editor-fold>

public class Customer implements Serializable {

// <editor-fold defaultstate="collapsed" desc="init variables">
    private int customerID;
    private String type = "";
    private String email = "";
    private String password = "";
    private String resellerCode = "";

    private String shippAccount = "";

    private Address shipping;
    private Address billing;

    private String ccName = "";
    private String cardNumber = "";
    private int ccNumberAdd;
    private String ccExpMonth = "";
    private String ccExpYears = "";
    private String bankPhone = "";

    private String notice = "";
    private String joined = "";

    private String checkRoutingNumber = "";
    private String checkAccountNumber = "";
    private String checkNumber = "";
    private String licenseNumber = "";
    private String licenseState = "";
// </editor-fold>

    public Customer() {
	shipping = new Address();
	billing = new Address();
    }

    public Address getBilling() {
	return billing;
    }

    public Address getShipping() {
	return shipping;
    }

    public int getCustomerID()                      { return customerID; }
    public void setCustomerID(int customerID)       { this.customerID = customerID; }

    public String getType()                         { return type; }
    public void setType(String type)                { this.type = type; }

    public String getResellerCode()                 { return resellerCode; }
    public void setResellerCode(String resellerCode){ this.resellerCode = cleanString(resellerCode); }

    public String getEmail()                        { return email; }
    public void setEmail(String email)              { this.email = cleanString(email); }

    public String getPassword()                     { return password; }
    public void setPassword(String password)        { this.password = cleanString(password.length() > 15 ? password.substring(0,15) : password); }

    public String getShippingAccount()              { return shippAccount; }
    public void setShippingAccount(String account)  { this.shippAccount = account; }


    public Address getShippingAddress()             { return shipping; }
    public void setShippingAddress(Address shipping){ this.shipping = shipping; }

    public Address getBillingAddress()              { return billing; }
    public void setBillingAddress(Address billing)  { this.billing = billing; }

    public String getCName()                        { return ccName; }
    public void setCName(String ccName)             { this.ccName = cleanString(ccName); }

    // recognaze Card type from first digit
    public String getCType() {
	String cardType = "";
        if(this.cardNumber.length() > 1) {

            char first = this.cardNumber.charAt(0);
            switch(first) {
                case '3' : cardType = "AMEX"; break;
                case '4' : cardType = "VISA"; break;
                case '5' : cardType = "MASTERCARD"; break;
                case '6' : cardType = "DISCOVER"; break;
                default : cardType = "";
            }
        }
        return cardType;
    }

    public String getCardNumber()			{ return cardNumber; }
    public void setCardNumber(String cardNumber)	{ this.cardNumber = cardNumber; }

    // change number card ftom 4111 1111 1111 1111 to **** **** **** 1111
    public String getCardNumberShow() {

        if("0".equals(this.cardNumber) || this.cardNumber.isEmpty()) return "";

        String show = "";
        try {
            show = new StringBuilder(16).append(this.cardNumber).delete(4,16).insert(4,"************").toString();
        }
        catch(Exception ex) {
            System.out.println("web.Customer():getCardNumberShow():this.cardNumber=" + this.cardNumber);
        }

        return show;
    }

    public int getCNumberAdd()				{ return ccNumberAdd; }
    public void setCNumberAdd(int ccNumberAdd)		{ this.ccNumberAdd = ccNumberAdd; }

    public String getCExpDate()				{ return getCExpMonth() + getCExpYears(); }

    public String getCExpMonth()			{ return ccExpMonth; }
    public void setCExpMonth(String ccExpMonth)		{ this.ccExpMonth = cleanString(ccExpMonth); }

    public String getCExpYears()			{ return ccExpYears; }
    public void setCExpYears(String ccExpYears)		{ this.ccExpYears = cleanString(ccExpYears); }

    public String getBankPhone()			{ return bankPhone; }
    public void setBankPhone(String bankPhone)		{ this.bankPhone = cleanString(bankPhone); }


    public String getNotice()                           { return notice.length() > 254 ? notice.substring(0,254) : notice; }
    public void setNotice(String notice)		{ this.notice = cleanString(notice); }

    public String getJoined()				{ return joined; }
    public void setJoined(String joined)		{ this.joined = joined; }

    public String getCheckRoutingNumber()		{ return checkRoutingNumber; }
    public void setCheckRoutingNumber(String value)	{ this.checkRoutingNumber = cleanString(value); }

    public String getCheckAccountNumber()		{ return checkAccountNumber; }
    public void setCheckAccountNumber(String value)	{ this.checkAccountNumber = cleanString(value); }

    public String getCheckNumber()			{ return checkNumber; }
    public void setCheckNumber(String value)		{ this.checkNumber = cleanString(value); }

    public String getLicenseNumber()			{ return licenseNumber; }
    public void setLicenseNumber(String value)		{ this.licenseNumber = cleanString(value); }

    public String getLicenseState()			{ return licenseState; }
    public void setLicenseState(String value)		{ this.licenseState = cleanString(value); }

// <editor-fold defaultstate="collapsed" desc="cleanString()">

    private String cleanString(String str) {
	return str == null ? "" : str.trim();
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="compareBillingAndShipping()">
// check shipping == billing

    public boolean compareBillingAndShipping() {
	String b = new StringBuilder(200).append(billing.getCountry()).append(billing.getState()).append(billing.getZip())
			.append(billing.getCity()).append(billing.getAddress2()).append(billing.getAddress1()).toString();
	String s = new StringBuilder(200).append(shipping.getCountry()).append(shipping.getState()).append(shipping.getZip())
			.append(shipping.getCity()).append(shipping.getAddress2()).append(shipping.getAddress1()).toString();
	return b.equalsIgnoreCase(s);
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="toString()">

    @Override
    public String toString() {

        StringBuilder buf = new StringBuilder();
        buf.append("---------------------------");
        buf.append("\ncustomerID: ").append(customerID);
        buf.append("\ntype: ").append(type);
        buf.append("\nemail: ").append(email);
        buf.append("\npassword: ").append(password);
        buf.append("\nresellerCode: ").append(resellerCode);

        buf.append("\nBilling Address:\n");
        buf.append(billing.toString());
        buf.append("\nShipping Address:\n");
        buf.append(shipping.toString());

        buf.append("\nccName: ").append(ccName);
        buf.append("\nccNumber: ").append(cardNumber);
        buf.append("\nccNumberAdd: ").append(ccNumberAdd);
        buf.append("\nccExpMonth: ").append(ccExpMonth);
        buf.append("\nccExpYears: ").append(ccExpYears);
        buf.append("\nbankPhone: ").append(bankPhone);

        buf.append("\nnotice: ").append(notice);
        buf.append("\njoined: ").append(joined);
        buf.append("\n---------------------------");

        return buf.toString();
    }
// </editor-fold>
}
